import { getPageSourceInfo } from "../../../shared/util";
let mobileLog = false;
const goldLog = (logType: "EXP" | "CLK", btn: string, method: "POST" | "GET") => {
	if (window && window.goldlog) {
		window.goldlog.record("/sc.supplier.newsign", logType, btn, method);
		return true;
	}
	return false;
};

const pageOpen = () => {
	// if (window.hasRecordPageExp && mobileLog) return;
	const { origin } = getPageSourceInfo();
	goldLog("EXP", `btn=leads_form_page_exp_wap&origin=${origin}`, "GET");
	console.log("首屏埋点success", origin)
	// res && ((window.hasRecordPageExp = true), (mobileLog = true));
};

const submitSuccess = () => {
	const { origin } = getPageSourceInfo();
	const status = "success";
	goldLog("CLK", `btn=submit_success_wap&status=${status}&origin=${origin}`, "POST");
};

const submitFail = (status: string) => {
	const { origin } = getPageSourceInfo();
	const btnParam = `btn=submit_fail_wap${!!status ? `&status=${status}` : ""}&origin=${origin}`;
	goldLog("CLK", btnParam, "POST");
};

const submitFailBycCode = () => submitFail("phone_code_valid_fail");

const submitFailByField = () => submitFail("validate_fail");

export { pageOpen, submitSuccess, submitFailByField, submitFailBycCode, submitFail };
